import { IMTableType } from "@/types/table";
import clubAvatar from "@/views/society/club/components/clubAvatar";
import {
  signStatusDict,
  roleDict,
  isYesDict,
  originDict,
} from "@/views/society/party/dict";
const columns = reactive<IMTableType[]>([
  { title: getProxyT("base.index"), dataIndex: "index", key: "index" },
  {
    title: getProxyT("table148"),
    dataIndex: "user_info",
    key: "user_info",
  },
  {
    title: getProxyT("table140"),
    dataIndex: "online_status",
    key: "online_status",
  },
  { title: getProxyT("table149"), dataIndex: "role", key: "role" },
  { title: getProxyT("table114"), dataIndex: "origin", key: "origin" },
  {
    title: getProxyT("table142"),
    dataIndex: "joined_time",
    key: "joined_time",
    customRender: ({ text }: any) => getTimeByZone(text),
  },
  {
    title: getProxyT("table150"),
    dataIndex: "is_need_air_ticket",
    key: "is_need_air_ticket",
  },
  {
    title: getProxyT("table151"),
    dataIndex: "is_need_hotel",
    key: "is_need_hotel",
  },
  {
    title: getProxyT("table152"),
    dataIndex: "sign_status",
    key: "sign_status",
  },
  {
    title: getProxyT("table153"),
    dataIndex: "signed_time",
    key: "signed_time",
    customRender: ({ text }: any) => getTimeByZone(text),
  },
]);

export const tableConfig = ({ handleAction, fetchList }: any) => {
  const defineTable = {
    components: {
      clubAvatar,
    },
    pagination: reactive({
      total: 0,
      current: 1,
      pageSize: 10,
      showTotal: (total: any) =>
        `${$t("base.total")}${total}${$t("base.items")}`,
      showQuickJumper: true,
      showLessItems: true,
    }),
    loading: ref(false),
    on: {
      change(paging: { current: number; pageSize: number }) {
        const { pagination } = defineTable;
        pagination.current = paging.current;
        pagination.pageSize = paging.pageSize;
        fetchList();
      },
    },
    columns: columns,
    style: {
      flex: 1,
    },
    dataSource: ref([]),
    tableSlot: {
      bodyCell({ value, text, index, column, record }: any) {
        switch (column.key) {
          case "index":
            const { pagination } = defineTable;
            return (
              <div>
                <i>
                  {index + 1 + (pagination.current - 1) * pagination.pageSize}
                </i>
              </div>
            );
          case "user_info":
            return (
              <div>
                <clubAvatar data={record.user_info} />
              </div>
            );
          case "role":
            return <div>{selectDictLabel(roleDict, record.role)}</div>;
          case "origin":
            return (
              <div>
                {isNumberString(value)
                  ? selectDictLabel(originDict, value)
                  : value}
              </div>
            );
          case "is_need_air_ticket":
            return (
              <div>{selectDictLabel(isYesDict, record.is_need_air_ticket)}</div>
            );
          case "is_need_hotel":
            return (
              <div>{selectDictLabel(isYesDict, record.is_need_hotel)}</div>
            );
          case "sign_status":
            return (
              <>
                <div>
                  <i class={record.sign_status === 1 ? "s-52c41a" : "s-c1c1c1"}>
                    {selectDictLabel(signStatusDict, record.sign_status)}
                  </i>
                </div>
              </>
            );
        }
      },
    },
  };
  return defineTable;
};
